package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.ProductDao;
import cn.itcast.domain.cargo.Product;
import cn.itcast.domain.cargo.ProductExample;
import cn.itcast.service.cargo.ProductService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Service
public class ProductServiceImpl implements ProductService {

    //依赖注入
    @Autowired
    private ProductDao productDao;

    @Override
    public void save(Product product) {
        //调用方法
        productDao.insertSelective(product);
    }

    @Override
    public void update(Product product) {
        //调用方法
        productDao.updateByPrimaryKey(product);
    }

    @Override
    public void delete(String id) {
        //删除
        productDao.deleteByPrimaryKey(id);
    }

    @Override
    public Product findById(String id) {
        //调用方法
        Product product = productDao.selectByPrimaryKey(id);

        return product;
    }

    @Override
    public List<Product> findAll(ProductExample example) {
        List<Product> products = productDao.selectByExample(example);
        return products;
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize, ProductExample example) {
        PageHelper.startPage(pageNum, pageSize);
        List<Product> list = productDao.selectByExample(example);
        return new PageInfo(list);
    }
}
